package com.ruoyi.web.controller.equip;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.SelectEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.equip.domain.EquipCategory;
import com.ruoyi.equip.service.IEquipCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/equip/category")
@Api(tags = "设备品类相关接口")
public class EquipCategoryController extends BaseController {

    @Autowired
    private IEquipCategoryService categoryService;


    @ApiOperation("查询所有设备品类")
    @GetMapping("/list")
    public TableDataInfo list(EquipCategory equipCategory) {
        startPage();
        List<EquipCategory> equipCategories = categoryService.selectAll(equipCategory);
        return getDataTable(equipCategories);
    }


    @ApiOperation("查询所有设备品类-下拉框")
    @GetMapping("/selectList")
    public AjaxResult selectList() {
        List<SelectEntity> selectList = categoryService.selectList();
        return success(selectList);
    }

    /**
     * 新增设备品类
     */
    @ApiOperation("新增设备品类")
    @Log(title = "新增设备品类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody EquipCategory equipCategory) {
        return toAjax(categoryService.addCategory(equipCategory));
    }

    /**
     * 修改设备品类
     */
    @ApiOperation("修改设备品类")
    @Log(title = "修改设备品类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody EquipCategory equipCategory){
        return toAjax(categoryService.upateCategory(equipCategory));
    }



    /**
     * 删除设备品类
     */
    @ApiOperation("删除设备品类")
    @Log(title = "删除指定设备品类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(categoryService.deleteId(id));
    }




}
